package cn.wu.jishupeizhi.rabbitmq;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.time.LocalTime;

@RunWith(SpringRunner.class)
@SpringBootTest
public class WorkQueue {


    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Test
    public void pushRabbitMq1() throws Exception {
        String queueName = "simple.queue";
        String message = "Hello World!spring amqp!!";
        for (int i = 0; i < 100; i++) {

            rabbitTemplate.convertAndSend(queueName, message+i);
            //sleep3秒
            Thread.sleep(20);
        }
    }

    @RabbitListener(queues = "simple.queue")
    public void pullRabbitMq1(String msg){
        System.out.println("消费者1：消费者接收到simple.queue的消息：{"+msg+"}"+LocalTime.now());
    }

    @RabbitListener(queues = "simple.queue")
    public void pullRabbitMq2(String msg){
        System.out.println("消费者2：消费者接收到simple.queue的消息：{"+msg+"}"+LocalTime.now());
    }






}
